<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>许愿墙</title>
  <style>
    * {padding: 0; margin: 0;}
    html, body{width: 100%; height: 100%;}
    .drap_box {
      width: 150px;
      height: 150px;
      font-size: 18px;
      line-height: 24px;
      padding: 50px;
      background-color: chartreuse;
      box-shadow: 5px 5px 15px 0 #606266;
    }
    .drap_box span {
      position: absolute;
      top: 10px;
      right: 10px;
    }
  </style>
  <link rel="stylesheet" href="jquery-ui-1.12.1/jquery-ui.min.css">
</head>
<body>
  <div id="wicket">
    <div class="add_input">
      <input type="text" class="text">
      <input type="button" class="button" value="添加">
    </div>
  </div>

  <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
  <script src="jquery-ui-1.12.1/jquery-ui.min.js"></script>
  <script>
    let $wicket = $("#wicket");
    let $input = $("#wicket .add_input");
    let $text = $("#wicket .add_input .text");
    let $btn = $("#wicket .add_input .button");

    $wicket.css({
      width: "100%",
      height: "100%",
      backgroundColor: "#409EFF",      
    });
    $input.css({display: "flex", width: "100%"});
    $text.button().css("flex", 1);

    

    $btn.button().click(() => {
      if ($text.val() !== "") {
        let drap = $("<div></div>");
        let p = $("<p>" + $text.val() + "</p>");
        let span = $("<span>✖<span>");
        $(drap).append(p).append(span);
        $wicket.append($(drap).draggable({
          containment: "#wicket",
          zIndex:99,
          create: function (e) {
            $(this).css({
              position: "absolute"
            });
            $(this).children("span").eq(0).click(() => {
              $(this).remove()
            })
          }
        }).addClass("drap_box"));
        $text.val("");
      }
    });

    

    
  </script>
</body>
</html>